//
//  CZStatusView.swift
//  Swift -- 微博
//
//  Created by sks on 16/6/28.
//  Copyright © 2016年 mohaha. All rights reserved.
//

import UIKit

private let OriginalMargin: CGFloat = 10
class CZStatusView: UIView {
    
    
    //传入模型 赋值
    var stutus : CZStatus? {
        
        didSet{
            //昵称
            nameLabel.text = stutus?.user?.name
            //头像
            headImageView.sd_setImageWithURL(NSURL(string: stutus?.user?.profile_image_url ?? ""), placeholderImage: UIImage(named: "avatar_default_big"))
            //微博内容
            contentLabel.text = stutus?.text
            //认证图片
//            vipImageView.image = stutus?.user?.verifiedImage
            
            
        }
        
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    // MARK: - 设置视图
    private func setupUI(){
        backgroundColor = RandomColor()
        // 01- 添加控件
        addSubview(headImageView)
        addSubview(nameLabel)
        addSubview(expiredImageView)
        addSubview(timeLabel)
        addSubview(sourceLabel)
        addSubview(vipImageView)
        addSubview(contentLabel)
        // 02 -添加约束
        // 头像
        headImageView.snp_makeConstraints { (make) -> Void in
            make.leading.top.equalTo(self).offset(OriginalMargin)
            make.size.equalTo(CGSize(width: 35, height: 35))
        }
        // 昵称
        nameLabel.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(headImageView)
            make.leading.equalTo(headImageView.snp_trailing).offset(OriginalMargin)
        }
        // 用户等级
        expiredImageView.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(nameLabel.snp_trailing).offset(OriginalMargin)
            make.centerY.equalTo(nameLabel)
        }
        // 发布时间
        timeLabel.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(nameLabel)
            make.bottom.equalTo(headImageView)
        }
        // 来自
        sourceLabel.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(timeLabel)
            make.leading.equalTo(timeLabel.snp_trailing).offset(OriginalMargin)
        }
        // 认证
        vipImageView.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(headImageView.snp_trailing)
            make.centerY.equalTo(headImageView.snp_bottom)
        }
        //微博内容
        contentLabel.snp_makeConstraints { (make) in
            make.left.equalTo(self).offset(10)
            make.right.equalTo(self).offset(-10)
            make.top.equalTo(headImageView.snp_bottom).offset(10)
        }
        
        // 临时放到这里
        nameLabel.text = "昵称"
        timeLabel.text = "时间"
        sourceLabel.text = "来自传智播客29期"
        contentLabel.text = "来自传智播客29期来自传智播客29期来自传智播客29期来自传智播客29期来自传智播客29期来自传智播客29期来自传智播客29期来自传智播客29期"
    }
    
    
    // MARK: - 懒加载控件
    // 头像
    private lazy var headImageView: UIImageView = UIImageView(image: UIImage(named:" avatar_default_big"))
    // 用户昵称
    private lazy var nameLabel : UILabel = {
    
        let lab = UILabel()
        lab.textColor = UIColor.darkGrayColor()
        lab.font = UIFont.systemFontOfSize(15)
        
       return lab
    }()
    
    
    // 用户等级
    private lazy var expiredImageView: UIImageView = UIImageView(image: UIImage(named: "common_icon_membership_expired"))
    // 发布微博事件
    private lazy var timeLabel : UILabel = {
        
        let lab = UILabel()
        lab.textColor = UIColor.orangeColor()
        lab.font = UIFont.systemFontOfSize(10)
        
        return lab
    }()
    
    // 来源
    private lazy var sourceLabel : UILabel = {
        
        let lab = UILabel()
        lab.textColor = UIColor.grayColor()
        lab.font = UIFont.systemFontOfSize(10)
        
        return lab
    }()
    
    // VIP
    private lazy var vipImageView: UIImageView = UIImageView(image: UIImage(named: "avatar_vgirl"))
    
    //微博内容
    private lazy var  contentLabel : UILabel  = {
        let lab = UILabel()
        lab.textColor = UIColor.blackColor()
        lab.font = UIFont.systemFontOfSize(15)
        lab.numberOfLines = 0
        
      return lab
    }()
 
}
